local skel = fk.CreateSkill{
  name = "lb__zhiming",
}

Fk:loadTranslationTable{
  ["lb__zhiming"] = "织命",
  --[":lb__zhiming"] = "每轮开始时，你可以重铸一张【杀】或【铁索连环】，然后你可以令其中一名角色将 “<b>衣匠</b>”作为副将：你，上家，下家。你的手牌上限增加场上“<b>衣匠</b>”数。",
  --9.7
   [":lb__zhiming"] = "每轮开始时，你可以令其中一名没有副将的角色将 “<b>衣匠</b>”作为副将：你，上家，下家。你的手牌上限增加场上“<b>衣匠</b>”数。",

  --["#lb__zhiming"] = "织命：你可以重铸一张【杀】或【铁索连环】",
  ["#lb__zhiming_change"] = "织命：你可以令一名角色将 “<b>衣匠</b>”作为副将",

  ["$lb__zhiming1"] = "裁断之时。",
  ["$lb__zhiming2"] = "予你盛装。",
}
--[[
skel:addEffect(fk.RoundStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and not player:isKongcheng()
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player,{
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      cancelable = true,
      prompt = "#lb__zhiming",
      pattern = "slash,iron_chain",
    })
    event:setCostData(self,{cards = cards})
    return #cards > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    room:recastCard(cards, player, skel.name)
    local tos = {}
    for _, to in ipairs({player:getLastAlive(), player, player:getNextAlive()}) do
      if not to.deputyGeneral or to.deputyGeneral == "" then
        table.insertIfNeed(tos, to)
      end
    end
    if #tos == 0 then return end
    tos = room:askToChoosePlayers(player,{
      targets = tos,
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      cancelable = true,
      prompt = "#lb__zhiming_change",
    })
    if #tos > 0 then
      room:changeHero(tos[1], "lb__yijiang", false, true, true, false)
    end
  end,
})
--]]

skel:addEffect(fk.RoundStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and 
    table.find({player:getLastAlive(), player, player:getNextAlive()}, function (to)
      return not to.deputyGeneral or to.deputyGeneral == ""
    end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = table.filter({player:getLastAlive(), player, player:getNextAlive()}, function (to)
      return not to.deputyGeneral or to.deputyGeneral == ""
    end)
    if #tos == 0 then return end
    tos = room:askToChoosePlayers(player,{
      targets = tos,
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      cancelable = true,
      prompt = "#lb__zhiming_change",
    })
    if #tos > 0 then
      event:setCostData(self,{tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local tos = event:getCostData(self).tos
    player.room:changeHero(tos[1], "lb__yijiang", false, true, true, false)
  end,
})


skel:addEffect("maxcards", {
  correct_func = function(self, player)
    if player:hasSkill(skel.name) then
      return #table.filter(Fk:currentRoom().alive_players, function (to)
        return to.general == "lb__yijiang" or to.deputyGeneral == "lb__yijiang"
      end)
    end
  end,
})

return skel